//
//  UIBarButtonItem+Extension.swift
//  PersonnalDiary
//
//  Created by 徐宽阔 on 15/9/27.
//  Copyright © 2015年 XDKOO. All rights reserved.
//

import UIKit

extension UIBarButtonItem
{
    
    class func createBarButtonItem(imageName:String , target:AnyObject? , actionName:String ) -> UIBarButtonItem {
        let btn = UIButton()
        btn.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        btn.setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
        btn.sizeToFit()
        btn.addTarget(target, action:Selector(actionName), forControlEvents: UIControlEvents.TouchUpInside)
        return UIBarButtonItem.init(customView:btn)
    }
    
    convenience init(imageName:String , target:AnyObject? , actionName:String) {
        
        let btn = UIButton()
        btn.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        btn.setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
        btn.sizeToFit()
        btn.addTarget(target, action:Selector(actionName), forControlEvents: UIControlEvents.TouchUpInside)
        
        self.init(customView:btn)
    }
    
    
}


